//公司详情
import React, {Component} from 'react';
import {Image, ImageBackground, Text, TouchableOpacity, View,} from 'react-native';

import {companyoneStyle as styles} from '../../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
import {common_url} from "../../../../util/fetch";

let Dimensions = require('Dimensions');
let width = Dimensions.get('window').width;

export default class Companyone extends Component {
    constructor(props) {
        super(props);
        this.state = {
            followState: this.props.followState
        }
    }

    render() {
        return (
            <View>

                <ImageBackground style={[styles.comtop, {width: width * 1}]}
                                 source={require('../../../../img/position/company.png')}>

                    <TouchableOpacity style={styles.comicon1} onPress={() => {
                        this.props.navigation.goBack()
                    }} activeOpacity={1}>
                        <Icon
                            name={'ios-arrow-back'}
                            size={25}
                            color={'#ffffff'}/>
                    </TouchableOpacity>

                    <View style={styles.comall}>
                        <Image source={
                            this.props.xzCompany.companyPicture ?
                                {uri: common_url + "uploadImg/" + this.props.xzCompany.companyPicture}
                                : require('../../../../img/app/company.png')} style={styles.head}/>
                        <View style={styles.comallin}>
                            <Text style={styles.comname}>{this.props.xzCompany.companyName}</Text>
                            <View style={styles.comother}>
                                <TouchableOpacity
                                    style={styles.combutton}
                                    onPress={() => {
                                        this.goTo()
                                    }}
                                    activeOpacity={1}
                                >
                                    {this.props.followState === 'ok' ?
                                        <Text style={styles.comtext1}>已关注</Text>
                                        :
                                        this.props.followState === 'err' ?
                                            <Text style={styles.comtext1}>
                                                <Icon
                                                    name={'md-add'}
                                                    size={10}
                                                    color={'#ffffff'}/>&nbsp;
                                                关注</Text>
                                            :
                                            null
                                    }
                                </TouchableOpacity>
                                <Text style={styles.comperson}>{this.props.xzCompany.followNum}人关注</Text>
                            </View>
                        </View>
                    </View>
                </ImageBackground>
            </View>
        )
    }

    goTo() {
        if (this.state.followState === this.props.followState) {
            if (this.state.followState === 'ok') {
                this.props.actions.DeleteFollowBykeyMob({companyId: this.props.xzCompany.companyId});
                this.setState({followState: 'err'});
            } else if (this.state.followState === 'err') {
                this.props.actions.InsertFollowCompanyAction({companyId: this.props.xzCompany.companyId});
                this.setState({followState: 'ok'});
            }
        }
    }
}
